home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / ppl4c10.zip / DATETIME.C < prev    next >
Text File  |  1995-02-06  |  2KB  |  73 lines

  1. /* datetime.c */
  2.  
  3. #include <stdio.h>
  4. #include <dos.h>
  5.  
  6. #define BYTE unsigned char
  7. #define WORD unsigned int
  8.  
  9. #include "datetime.h"
  10.  
  11. #define FALSE 0
  12. #define TRUE !FALSE
  13.  
  14. int GetFileDT(int Handle, WORD *Date, WORD *Time)
  15. {union REGS reg;
  16.  reg.h.ah = 0x57;
  17.  reg.h.al = 0x00;
  18.  reg.x.bx = Handle;
  19.  int86(0x21, ®, ®);
  20.  *Time = reg.x.cx;
  21.  *Date = reg.x.dx;
  22.  if(reg.x.cflag) return FALSE;
  23.  return TRUE;
  24. }
  25.  
  26. int SetFileDT(int Handle, WORD Date, WORD Time)
  27. {union REGS reg;
  28.  reg.h.ah = 0x57;
  29.  reg.h.al = 0x01;
  30.  reg.x.bx = Handle;
  31.  reg.x.cx = Time;
  32.  reg.x.dx = Date;
  33.  int86(0x21, ®, ®);
  34.  if(reg.x.cflag) return FALSE;
  35.  return TRUE;
  36. }
  37.  
  38. void PackDate(BYTE Year,BYTE Month,BYTE Day,WORD *Date)
  39. {WORD LoDate;
  40.  WORD HiDate;
  41.  Year -= 80;
  42.  HiDate = 0x00ff & ((Year<<1) | (Month>>3));
  43.  LoDate = 0x00ff & ((Month<<5) | Day);
  44.  *Date = ((HiDate<<8) + LoDate);
  45. }
  46.  
  47. void PackTime(BYTE Hours,BYTE Minutes,BYTE Seconds,WORD *Time)
  48. {WORD LoTime;
  49.  WORD HiTime;
  50.  HiTime = 0x00ff & ((Hours<<3) | (Minutes>>3));
  51.  LoTime = 0x00ff & ((Minutes<<5) | Seconds);
  52.  *Time = ((HiTime<<8) + LoTime);
  53. }
  54.  
  55. void UnpackDate(WORD Date,BYTE *Year,BYTE *Month,BYTE *Day)
  56. {BYTE LoDate;
  57.  BYTE HiDate;
  58.  LoDate = 0x00ff & Date;
  59.  HiDate = Date >> 8;
  60.  *Year = 80 + (HiDate >> 1);
  61.  *Month = 0x0f & ((HiDate<<3) | (LoDate>>5));
  62.  *Day = 0x1f & LoDate;
  63. }
  64.  
  65. void UnpackTime(WORD Time,BYTE *Hours,BYTE *Minutes,BYTE *Seconds)
  66. {BYTE LoTime;
  67.  BYTE HiTime;
  68.  LoTime = 0x00ff & Time;
  69.  HiTime = Time >> 8;
  70.  *Hours = (HiTime >> 3);
  71.  *Minutes = 0x3f & ((HiTime << 3) | (LoTime >> 5));
  72.  *Seconds = 0x1f & LoTime;
  73. }